<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../Universal.css">
</head>
<body>
    
    <div id="cnblogs_post_body" class="blogpost-body">
        <h1>MySQL</h1>
    <h2>在dos中操作mysql</h2>
    <p>连接mysql命令：&nbsp;<span class="cnblogs_code">mysql <span style="color: rgba(128, 128, 128, 1)">-</span>uroot <span style="color: rgba(128, 128, 128, 1)">-</span>p密码</span>&nbsp;<strong>，</strong>连接OK，会出现mysql&gt;</p>
    <h3>对数据库的操作</h3>
    <p>创建一个库</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">create</span> <span style="color: rgba(0, 0, 255, 1)">database</span><span style="color: rgba(0, 0, 0, 1)"> 库名
    </span><span style="color: rgba(0, 0, 255, 1)">create</span> <span style="color: rgba(0, 0, 255, 1)">database</span> 库名 <span style="color: rgba(0, 0, 255, 1)">character</span> <span style="color: rgba(0, 0, 255, 1)">set</span> 编码</pre>
    </div>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">create</span> <span style="color: rgba(0, 0, 255, 1)">database</span><span style="color: rgba(0, 0, 0, 1)"> mybase;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)"> show databases;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Database</span>           <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> information_schema <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> mybase             <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> mysql              <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> performance_schema <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> test               <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">5</span> rows <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>创建带有编码的</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">create</span> <span style="color: rgba(0, 0, 255, 1)">database</span> mybase01 <span style="color: rgba(0, 0, 255, 1)">character</span> <span style="color: rgba(0, 0, 255, 1)">set</span> gbk;</pre>
    </div>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">create</span> <span style="color: rgba(0, 0, 255, 1)">database</span> mybase01 <span style="color: rgba(0, 0, 255, 1)">character</span> <span style="color: rgba(0, 0, 255, 1)">set</span><span style="color: rgba(0, 0, 0, 1)"> gbk;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)"> show databases;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Database</span>           <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> information_schema <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> mybase             <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> mybase01           <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> mysql              <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> performance_schema <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> test               <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span> rows <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>查看编码：</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> show <span style="color: rgba(0, 0, 255, 1)">create</span> <span style="color: rgba(0, 0, 255, 1)">database</span><span style="color: rgba(0, 0, 0, 1)"> mybase01;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+------------------------------------------------------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Database</span> <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Create</span> <span style="color: rgba(0, 0, 255, 1)">Database</span>                                                  <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+------------------------------------------------------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> mybase01 <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">CREATE</span> <span style="color: rgba(0, 0, 255, 1)">DATABASE</span> `mybase01` <span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">!40100 DEFAULT CHARACTER SET gbk </span><span style="color: rgba(0, 128, 128, 1)">*/</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+------------------------------------------------------------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>&nbsp;查看数据库</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)"> show databases;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Database</span>           <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> information_schema <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> mybase             <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> mysql              <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> performance_schema <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> test               <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">5</span> rows <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>删除一个库</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">drop</span> <span style="color: rgba(0, 0, 255, 1)">database</span> 库名</pre>
    </div>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">drop</span> <span style="color: rgba(0, 0, 255, 1)">database</span><span style="color: rgba(0, 0, 0, 1)"> mybase;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)"> show databases;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Database</span>           <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> information_schema <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> mysql              <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> performance_schema <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> test               <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">------------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">4</span> rows <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>使用库&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">use</span> 库名</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">use</span><span style="color: rgba(0, 0, 0, 1)"> mybase
    </span><span style="color: rgba(0, 0, 255, 1)">Database</span> changed</pre>
    </div>
    <p>查看当前正在操作的库&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">select</span> <span style="color: rgba(0, 0, 255, 1)">database</span>();</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">select</span> <span style="color: rgba(0, 0, 255, 1)">database</span><span style="color: rgba(0, 0, 0, 1)">();
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">database</span>() <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> mybase     <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <h2><span style="font-size: 1.17em">对数据库表的操作</span></h2>
    <p>创建一张表</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 0, 1)"> 创建数据表的格式
          
    </span><span style="color: rgba(0, 0, 255, 1)">create</span> <span style="color: rgba(0, 0, 255, 1)">table</span><span style="color: rgba(0, 0, 0, 1)"> 表名(
           列名1 数据类型 约束,
           列名2 数据类型 约束,
           列名3 数据类型 约束
          );</span></pre>
    </div>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
          创建用户表,用户编号,姓名,用户的地址
          将编号列,设置为主键约束,保证列的数据唯一性,非空性
          primary key AUTO_INCREMENT
          让主键列数据,实现自动增长
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
     <span style="color: rgba(0, 0, 255, 1)">CREATE</span> <span style="color: rgba(0, 0, 255, 1)">TABLE</span><span style="color: rgba(0, 0, 0, 1)"> users (
         uid </span><span style="color: rgba(0, 0, 255, 1)">INT</span> <span style="color: rgba(0, 0, 255, 1)">PRIMARY</span> <span style="color: rgba(0, 0, 255, 1)">KEY</span><span style="color: rgba(0, 0, 0, 1)"> AUTO_INCREMENT ,
         uname </span><span style="color: rgba(0, 0, 255, 1)">VARCHAR</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">20</span><span style="color: rgba(0, 0, 0, 1)">),
         uaddress </span><span style="color: rgba(0, 0, 255, 1)">VARCHAR</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">200</span><span style="color: rgba(0, 0, 0, 1)">)
     );</span></pre>
    </div>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span>  <span style="color: rgba(0, 0, 255, 1)">CREATE</span> <span style="color: rgba(0, 0, 255, 1)">TABLE</span><span style="color: rgba(0, 0, 0, 1)"> users (
        </span><span style="color: rgba(128, 128, 128, 1)">-&gt;</span>      uid <span style="color: rgba(0, 0, 255, 1)">INT</span> <span style="color: rgba(0, 0, 255, 1)">PRIMARY</span> <span style="color: rgba(0, 0, 255, 1)">KEY</span><span style="color: rgba(0, 0, 0, 1)"> AUTO_INCREMENT ,
        </span><span style="color: rgba(128, 128, 128, 1)">-&gt;</span>      uname <span style="color: rgba(0, 0, 255, 1)">VARCHAR</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">20</span><span style="color: rgba(0, 0, 0, 1)">),
        </span><span style="color: rgba(128, 128, 128, 1)">-&gt;</span>      uaddress <span style="color: rgba(0, 0, 255, 1)">VARCHAR</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">200</span><span style="color: rgba(0, 0, 0, 1)">)
        </span><span style="color: rgba(128, 128, 128, 1)">-&gt;</span><span style="color: rgba(0, 0, 0, 1)">  );
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.02</span> sec)</pre>
    </div>
    <p>查看数据库表&nbsp;&nbsp;<span class="cnblogs_code">show tables;</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)"> show tables;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> Tables_in_mybase <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> users            <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>查看表的结构&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">desc</span> 表名</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">desc</span><span style="color: rgba(0, 0, 0, 1)"> users;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> Field    <span style="color: rgba(128, 128, 128, 1)">|</span> Type         <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Null</span> <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Key</span> <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Default</span> <span style="color: rgba(128, 128, 128, 1)">|</span> Extra          <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uid      <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">int</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">11</span>)      <span style="color: rgba(128, 128, 128, 1)">|</span> NO   <span style="color: rgba(128, 128, 128, 1)">|</span> PRI <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span> auto_increment <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uname    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">20</span>)  <span style="color: rgba(128, 128, 128, 1)">|</span> YES  <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span>                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uaddress <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">200</span>) <span style="color: rgba(128, 128, 128, 1)">|</span> YES  <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span>                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">3</span> rows <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>删除一张表&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">drop</span> <span style="color: rgba(0, 0, 255, 1)">table</span> 表名</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">drop</span> <span style="color: rgba(0, 0, 255, 1)">table</span><span style="color: rgba(0, 0, 0, 1)"> users；</span><span style="color: rgba(0, 0, 0, 1)"> 
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)"> show tables;
    Empty </span><span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <h3>修改表</h3>
    <p>添加一列&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">alter</span> <span style="color: rgba(0, 0, 255, 1)">table</span> 表名 <span style="color: rgba(0, 0, 255, 1)">add</span> 字段名 类型(长度) <span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">约束</span><span style="color: rgba(255, 0, 0, 1)">]</span></span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">alter</span> <span style="color: rgba(0, 0, 255, 1)">table</span> users <span style="color: rgba(0, 0, 255, 1)">add</span> tel <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)">;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    Records: </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Duplicates: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Warnings: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span></pre>
    </div>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">desc</span><span style="color: rgba(0, 0, 0, 1)"> users ;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> Field    <span style="color: rgba(128, 128, 128, 1)">|</span> Type         <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Null</span> <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Key</span> <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Default</span> <span style="color: rgba(128, 128, 128, 1)">|</span> Extra          <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uid      <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">int</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">11</span>)      <span style="color: rgba(128, 128, 128, 1)">|</span> NO   <span style="color: rgba(128, 128, 128, 1)">|</span> PRI <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span> auto_increment <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uname    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">20</span>)  <span style="color: rgba(128, 128, 128, 1)">|</span> YES  <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span>                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uaddress <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">200</span>) <span style="color: rgba(128, 128, 128, 1)">|</span> YES  <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span>                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> tel      <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">int</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">11</span>)      <span style="color: rgba(128, 128, 128, 1)">|</span> YES  <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span>                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">4</span> rows <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.01</span> sec)</pre>
    </div>
    <p>修改列的类型(长度、约束)&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">alter</span> <span style="color: rgba(0, 0, 255, 1)">table</span> 表名 modify 要修改的字段名 类型(长度) <span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">约束</span><span style="color: rgba(255, 0, 0, 1)">]</span></span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">alter</span> <span style="color: rgba(0, 0, 255, 1)">table</span> users modify tel <span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">50</span><span style="color: rgba(0, 0, 0, 1)">);
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.27</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    Records: </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Duplicates: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Warnings: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span></pre>
    </div>
    <p><span style="line-height: 1.5">修改列的列名&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">alter</span> <span style="color: rgba(0, 0, 255, 1)">table</span> 表名 change 旧列名 新列名 数据类型 约束</span>&nbsp;</span></p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">alter</span> <span style="color: rgba(0, 0, 255, 1)">table</span> users change tel newtel <span style="color: rgba(0, 0, 255, 1)">double</span><span style="color: rgba(0, 0, 0, 1)">;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.01</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    Records: </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Duplicates: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Warnings: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span></pre>
    </div>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">desc</span><span style="color: rgba(0, 0, 0, 1)"> users ;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> Field    <span style="color: rgba(128, 128, 128, 1)">|</span> Type         <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Null</span> <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Key</span> <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Default</span> <span style="color: rgba(128, 128, 128, 1)">|</span> Extra          <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uid      <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">int</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">11</span>)      <span style="color: rgba(128, 128, 128, 1)">|</span> NO   <span style="color: rgba(128, 128, 128, 1)">|</span> PRI <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span> auto_increment <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uname    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">20</span>)  <span style="color: rgba(128, 128, 128, 1)">|</span> YES  <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span>                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uaddress <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">200</span>) <span style="color: rgba(128, 128, 128, 1)">|</span> YES  <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span>                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> newtel   <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">double</span>       <span style="color: rgba(128, 128, 128, 1)">|</span> YES  <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span>                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">4</span> rows <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p><span style="line-height: 1.5">删除表的列&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">alter</span> <span style="color: rgba(0, 0, 255, 1)">table</span> 表名 <span style="color: rgba(0, 0, 255, 1)">drop</span> 列名</span>&nbsp;</span></p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">alter</span> <span style="color: rgba(0, 0, 255, 1)">table</span> users <span style="color: rgba(0, 0, 255, 1)">drop</span><span style="color: rgba(0, 0, 0, 1)"> newtel;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.02</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    Records: </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Duplicates: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Warnings: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span><span style="color: rgba(0, 0, 0, 1)">
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">desc</span><span style="color: rgba(0, 0, 0, 1)"> users;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> Field    <span style="color: rgba(128, 128, 128, 1)">|</span> Type         <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Null</span> <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Key</span> <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Default</span> <span style="color: rgba(128, 128, 128, 1)">|</span> Extra          <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uid      <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">int</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">11</span>)      <span style="color: rgba(128, 128, 128, 1)">|</span> NO   <span style="color: rgba(128, 128, 128, 1)">|</span> PRI <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span> auto_increment <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uname    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">20</span>)  <span style="color: rgba(128, 128, 128, 1)">|</span> YES  <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span>                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> uaddress <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">200</span>) <span style="color: rgba(128, 128, 128, 1)">|</span> YES  <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>    <span style="color: rgba(128, 128, 128, 1)">|</span>                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------+------+-----+---------+----------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">3</span> rows <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p><span style="line-height: 1.5">修改表名&nbsp;&nbsp;<span class="cnblogs_code">rename <span style="color: rgba(0, 0, 255, 1)">table</span> 表名 <span style="color: rgba(0, 0, 255, 1)">to</span> 新表名</span>&nbsp;</span></p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> rename <span style="color: rgba(0, 0, 255, 1)">table</span> users <span style="color: rgba(0, 0, 255, 1)">to</span><span style="color: rgba(0, 0, 0, 1)"> newusers;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.01</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)"> show tables;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> Tables_in_mybase <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> newusers         <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>查看表的字符集编码&nbsp;&nbsp;<span class="cnblogs_code">show <span style="color: rgba(0, 0, 255, 1)">create</span> <span style="color: rgba(0, 0, 255, 1)">table</span> newusers;</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> show <span style="color: rgba(0, 0, 255, 1)">create</span> <span style="color: rgba(0, 0, 255, 1)">table</span><span style="color: rgba(0, 0, 0, 1)"> newusers;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">-----------------------------------------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Table</span>    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Create</span> <span style="color: rgba(0, 0, 255, 1)">Table</span>
    
                                                           <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">-----------------------------------------------------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> newusers <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">CREATE</span> <span style="color: rgba(0, 0, 255, 1)">TABLE</span><span style="color: rgba(0, 0, 0, 1)"> `newusers` (
      `uid` </span><span style="color: rgba(0, 0, 255, 1)">int</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">11</span>) <span style="color: rgba(128, 128, 128, 1)">NOT</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span><span style="color: rgba(0, 0, 0, 1)"> AUTO_INCREMENT,
      `uname` </span><span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">20</span>) <span style="color: rgba(0, 0, 255, 1)">DEFAULT</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span><span style="color: rgba(0, 0, 0, 1)">,
      `uaddress` </span><span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">200</span>) <span style="color: rgba(0, 0, 255, 1)">DEFAULT</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span><span style="color: rgba(0, 0, 0, 1)">,
      </span><span style="color: rgba(0, 0, 255, 1)">PRIMARY</span> <span style="color: rgba(0, 0, 255, 1)">KEY</span><span style="color: rgba(0, 0, 0, 1)"> (`uid`)
    ) ENGINE</span><span style="color: rgba(128, 128, 128, 1)">=</span>InnoDB <span style="color: rgba(0, 0, 255, 1)">DEFAULT</span> CHARSET<span style="color: rgba(128, 128, 128, 1)">=</span>utf8 <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+--------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">-----------------------------------------------------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>修改表的字符集&nbsp;&nbsp;<span class="cnblogs_code">alter&nbsp;table&nbsp;表名&nbsp;character&nbsp;set&nbsp;编码&nbsp;</span></p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">alter</span> <span style="color: rgba(0, 0, 255, 1)">table</span> newusers <span style="color: rgba(0, 0, 255, 1)">character</span> <span style="color: rgba(0, 0, 255, 1)">set</span><span style="color: rgba(0, 0, 0, 1)"> gbk;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.03</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    Records: </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Duplicates: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Warnings: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span><span style="color: rgba(0, 0, 0, 1)">
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> show <span style="color: rgba(0, 0, 255, 1)">create</span> <span style="color: rgba(0, 0, 255, 1)">table</span><span style="color: rgba(0, 0, 0, 1)"> newusers;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+-------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">-----------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">-----------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">----------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Table</span>    <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">Create</span> <span style="color: rgba(0, 0, 255, 1)">Table</span>
    
    
                <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+-------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">-----------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">-----------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">----------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> newusers <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(0, 0, 255, 1)">CREATE</span> <span style="color: rgba(0, 0, 255, 1)">TABLE</span><span style="color: rgba(0, 0, 0, 1)"> `newusers` (
      `uid` </span><span style="color: rgba(0, 0, 255, 1)">int</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">11</span>) <span style="color: rgba(128, 128, 128, 1)">NOT</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span><span style="color: rgba(0, 0, 0, 1)"> AUTO_INCREMENT,
      `uname` </span><span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">20</span>) <span style="color: rgba(0, 0, 255, 1)">CHARACTER</span> <span style="color: rgba(0, 0, 255, 1)">SET</span> utf8 <span style="color: rgba(0, 0, 255, 1)">DEFAULT</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span><span style="color: rgba(0, 0, 0, 1)">,
      `uaddress` </span><span style="color: rgba(0, 0, 255, 1)">varchar</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">200</span>) <span style="color: rgba(0, 0, 255, 1)">CHARACTER</span> <span style="color: rgba(0, 0, 255, 1)">SET</span> utf8 <span style="color: rgba(0, 0, 255, 1)">DEFAULT</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span><span style="color: rgba(0, 0, 0, 1)">,
      </span><span style="color: rgba(0, 0, 255, 1)">PRIMARY</span> <span style="color: rgba(0, 0, 255, 1)">KEY</span><span style="color: rgba(0, 0, 0, 1)"> (`uid`)
    ) ENGINE</span><span style="color: rgba(128, 128, 128, 1)">=</span>InnoDB <span style="color: rgba(0, 0, 255, 1)">DEFAULT</span> CHARSET<span style="color: rgba(128, 128, 128, 1)">=</span>gbk <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--------+-------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">-----------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">-----------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)">----------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <h2><span style="font-size: 1.17em">对数据库表记录进行操作(修改)</span></h2>
    <p>插入记录</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">insert</span> <span style="color: rgba(0, 0, 255, 1)">into</span> 表名(列名1,列名2,列名3……) <span style="color: rgba(0, 0, 255, 1)">values</span><span style="color: rgba(0, 0, 0, 1)">(值1,值2,值3……)
    </span><span style="color: rgba(0, 0, 255, 1)">insert</span> <span style="color: rgba(0, 0, 255, 1)">into</span> 表名 <span style="color: rgba(0, 0, 255, 1)">values</span>(值1,值2,值3……)<br>insert into 表名 (列名1,列名2,列名3) values (值1,值2,值3),(值1,值2,值3)</pre>
    </div>
    <p>先创建product表，然后添加数据。</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">CREATE</span> <span style="color: rgba(0, 0, 255, 1)">TABLE</span><span style="color: rgba(0, 0, 0, 1)"> product(
       </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 主键列,自动增长</span>
       id <span style="color: rgba(0, 0, 255, 1)">INT</span> <span style="color: rgba(0, 0, 255, 1)">PRIMARY</span> <span style="color: rgba(0, 0, 255, 1)">KEY</span><span style="color: rgba(0, 0, 0, 1)"> AUTO_INCREMENT,
       </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 商品名字,可变字符,非空</span>
       pname <span style="color: rgba(0, 0, 255, 1)">VARCHAR</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">100</span>) <span style="color: rgba(128, 128, 128, 1)">NOT</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span><span style="color: rgba(0, 0, 0, 1)">,
       </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 商品的价格,double</span>
       price <span style="color: rgba(0, 0, 255, 1)">DOUBLE</span><span style="color: rgba(0, 0, 0, 1)">
    );</span></pre>
    </div>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> product (id,pname,price) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">笔记本</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5555.99</span><span style="color: rgba(0, 0, 0, 1)">);
    ERROR </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1366</span> (HY000): Incorrect string value: <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">\xB1\xCA\xBC\xC7\xB1\xBE</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> column </span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">pname</span><span style="color: rgba(255, 0, 0, 1)">'</span> at row <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span><span style="color: rgba(0, 0, 0, 1)">
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> product (id,pname,price) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">智能手机</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">9999</span><span style="color: rgba(0, 0, 0, 1)">);
    ERROR </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1366</span> (HY000): Incorrect string value: <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">\xD6\xC7\xC4\xDC\xCA\xD6...</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> column </span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">pname</span><span style="color: rgba(255, 0, 0, 1)">'</span> at row <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span><span style="color: rgba(0, 0, 0, 1)">
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> product (id,pname,price) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">computer</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5555.99</span><span style="color: rgba(0, 0, 0, 1)">);
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> product (id,pname,price) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">phone</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5555.99</span><span style="color: rgba(0, 0, 0, 1)">);
    ERROR </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1062</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">23000</span>): Duplicate entry <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">1</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(0, 0, 255, 1)">key</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">PRIMARY</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> product (id,pname,price) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">phone</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5555.99</span><span style="color: rgba(0, 0, 0, 1)">);
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <h3>插入数据中文乱码问题解决办法</h3>
    <p>乱码原因：客户端和服务器之间传递字符的编码规则不一样。</p>
    <p>方式一：直接修改数据库安装目录里面的my.ini文件的第57行【不建议】<br><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170702184029524-816534762.png" alt=""></p>
    <p>方式二：&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">set</span> names gbk;</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">set</span><span style="color: rgba(0, 0, 0, 1)"> names gbk;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>再次插入中文，可以看到，不报错了。</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> product (id,pname,price) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">3</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">笔记本</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5555.99</span><span style="color: rgba(0, 0, 0, 1)">);
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> product (id,pname,price) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">4</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">智能手机</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">9999</span><span style="color: rgba(0, 0, 0, 1)">);
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>添加数据格式,不考虑主键&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">insert</span> <span style="color: rgba(0, 0, 255, 1)">into</span> 表名 (列名) <span style="color: rgba(0, 0, 255, 1)">values</span> (值)</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> product (pname,price) <span style="color: rgba(0, 0, 255, 1)">VALUES</span>(<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">洗衣机</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">800</span><span style="color: rgba(0, 0, 0, 1)">);
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>添加数据格式,所有值全给出&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">insert</span> <span style="color: rgba(0, 0, 255, 1)">into</span> 表名 <span style="color: rgba(0, 0, 255, 1)">values</span> (全列值)</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> product <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">微波炉</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">300.25</span><span style="color: rgba(0, 0, 0, 1)">);
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>添加数据格式,批量写入&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">insert</span> <span style="color: rgba(0, 0, 255, 1)">into</span> 表名 (列名1,列名2,列名3) <span style="color: rgba(0, 0, 255, 1)">values</span> (值1,值2,值3),(值1,值2,值3)</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> product (pname,price) <span style="color: rgba(0, 0, 255, 1)">VALUES</span>
        <span style="color: rgba(128, 128, 128, 1)">-&gt;</span> (<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">智能机器人</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">25999.22</span><span style="color: rgba(0, 0, 0, 1)">),
        </span><span style="color: rgba(128, 128, 128, 1)">-&gt;</span> (<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">彩色电视</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1250.36</span><span style="color: rgba(0, 0, 0, 1)">),
        </span><span style="color: rgba(128, 128, 128, 1)">-&gt;</span> (<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">沙发</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5899.02</span><span style="color: rgba(0, 0, 0, 1)">);
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">3</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    Records: </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">3</span>  Duplicates: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>  Warnings: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span></pre>
    </div>
    <h3>修改表记录</h3>
    <p>先看看表中的所有数据：</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">select</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> product;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--+------------+----------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> id <span style="color: rgba(128, 128, 128, 1)">|</span> pname      <span style="color: rgba(128, 128, 128, 1)">|</span> price    <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--+------------+----------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> <span style="color: rgba(128, 128, 128, 1)">|</span> computer   <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">5555.99</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span> <span style="color: rgba(128, 128, 128, 1)">|</span> phone      <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">5555.99</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">3</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 笔记本         <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">5555.99</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">4</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 智能手机          <span style="color: rgba(128, 128, 128, 1)">|</span>     <span style="color: rgba(128, 0, 0, 1); font-weight: bold">9999</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">5</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 洗衣机         <span style="color: rgba(128, 128, 128, 1)">|</span>      <span style="color: rgba(128, 0, 0, 1); font-weight: bold">800</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 微波炉         <span style="color: rgba(128, 128, 128, 1)">|</span>   <span style="color: rgba(128, 0, 0, 1); font-weight: bold">300.25</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">7</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 智能机器人          <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">25999.22</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">8</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 彩色电视          <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1250.36</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">9</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 沙发          <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">5899.02</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--+------------+----------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">9</span> rows <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p><span style="line-height: 1.5">带条件的&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">update</span> 表名 set字段名<span style="color: rgba(128, 128, 128, 1)">=</span>值, 字段名<span style="color: rgba(128, 128, 128, 1)">=</span>值, 字段名<span style="color: rgba(128, 128, 128, 1)">=</span>值…… <span style="color: rgba(0, 0, 255, 1)">where</span> 条件</span>&nbsp;</span></p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 修改智能手机,价格上调到15999</span>
    mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">UPDATE</span> product <span style="color: rgba(0, 0, 255, 1)">SET</span> price <span style="color: rgba(128, 128, 128, 1)">=</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">15999</span> <span style="color: rgba(0, 0, 255, 1)">WHERE</span> id<span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span><span style="color: rgba(0, 0, 0, 1)">;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    Rows matched: </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span>  Changed: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span>  Warnings: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span></pre>
    </div>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 修改彩色电视,名字改为黑白电视机,价格,100</span>
    mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">UPDATE</span> product <span style="color: rgba(0, 0, 255, 1)">SET</span> pname<span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">黑白电视机</span><span style="color: rgba(255, 0, 0, 1)">'</span>, price<span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">100</span> <span style="color: rgba(0, 0, 255, 1)">WHERE</span> id <span style="color: rgba(128, 128, 128, 1)">=</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span><span style="color: rgba(0, 0, 0, 1)">;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> row affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    Rows matched: </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span>  Changed: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span>  Warnings: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span></pre>
    </div>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 0, 1)"> 修改条件的写法
        id</span><span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span><span style="color: rgba(0, 0, 0, 1)">
        id</span><span style="color: rgba(128, 128, 128, 1)">&lt;&gt;</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span><span style="color: rgba(0, 0, 0, 1)">
        id</span><span style="color: rgba(128, 128, 128, 1)">&lt;=</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span><span style="color: rgba(0, 0, 0, 1)">  
        与或非  </span><span style="color: rgba(128, 128, 128, 1)">&amp;&amp;</span> <span style="color: rgba(128, 128, 128, 1)">||</span><span style="color: rgba(0, 0, 0, 1)"> !
        </span><span style="color: rgba(128, 128, 128, 1)">&amp;&amp;</span> <span style="color: rgba(128, 128, 128, 1)">and</span>
        <span style="color: rgba(128, 128, 128, 1)">||</span> <span style="color: rgba(128, 128, 128, 1)">or</span><span style="color: rgba(0, 0, 0, 1)"> 
        ! </span><span style="color: rgba(128, 128, 128, 1)">not</span><span style="color: rgba(0, 0, 0, 1)">
        
        id </span><span style="color: rgba(128, 128, 128, 1)">in</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">3</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">4</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span>) 包含</pre>
    </div>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 将笔记本的价格,和空调的价格,全部修改为2000</span>
    <span style="color: rgba(0, 0, 255, 1)">UPDATE</span> product <span style="color: rgba(0, 0, 255, 1)">SET</span> price <span style="color: rgba(128, 128, 128, 1)">=</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">2000</span> <span style="color: rgba(0, 0, 255, 1)">WHERE</span> id <span style="color: rgba(128, 128, 128, 1)">=</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> <span style="color: rgba(128, 128, 128, 1)">OR</span> id <span style="color: rgba(128, 128, 128, 1)">=</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">7</span>;</pre>
    </div>
    <p>不带条件的，它会将该列的所有记录都更改 &nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">update</span> 表名 <span style="color: rgba(0, 0, 255, 1)">set</span> 字段名<span style="color: rgba(128, 128, 128, 1)">=</span>值, 字段名<span style="color: rgba(128, 128, 128, 1)">=</span>值, 字段名<span style="color: rgba(128, 128, 128, 1)">=</span>值…… </span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">update</span> product <span style="color: rgba(0, 0, 255, 1)">set</span> price<span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">999.999</span><span style="color: rgba(0, 0, 0, 1)">;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">9</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.01</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    Rows matched: </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">9</span>  Changed: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">9</span>  Warnings: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span></pre>
    </div>
    <h3><span style="font-size: 1.17em">删除表记录</span></h3>
    <p>带条件的&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">delete</span> <span style="color: rgba(0, 0, 255, 1)">from</span> 表名 <span style="color: rgba(0, 0, 255, 1)">where</span> 条件</span>&nbsp;</p>
    <p>不带条件的，会删除该表的所有记录&nbsp;&nbsp;<span class="cnblogs_code"><span style="color: rgba(0, 0, 255, 1)">delete</span> <span style="color: rgba(0, 0, 255, 1)">from</span> 表名;</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 删除热水器</span>
    <span style="color: rgba(0, 0, 255, 1)">DELETE</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> product <span style="color: rgba(0, 0, 255, 1)">WHERE</span> id<span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">8</span>;</pre>
    </div>
    <p><strong><span style="font-size: 1.17em">delete与truncate的区别</span></strong></p>
    <ul>
    <li>delete删除的时候是一条一条的删除记录，它配合事务，可以将删除的数据找回。</li>
    <li>truncate删除，它是将整个表摧毁，然后再创建一张一模一样的表。它删除的数据无法找回。</li>
    </ul>
    <p>Delete操作演示：&nbsp;</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> start <span style="color: rgba(0, 0, 255, 1)">transaction</span><span style="color: rgba(0, 0, 0, 1)">;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">delete</span> <span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> product;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">9</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">select</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> product;
    Empty </span><span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">rollback</span><span style="color: rgba(0, 0, 0, 1)">;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">select</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> product;
    </span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--+------------+---------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span> id <span style="color: rgba(128, 128, 128, 1)">|</span> pname      <span style="color: rgba(128, 128, 128, 1)">|</span> price   <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--+------------+---------+</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> <span style="color: rgba(128, 128, 128, 1)">|</span> computer   <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">999.999</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span> <span style="color: rgba(128, 128, 128, 1)">|</span> phone      <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">999.999</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">3</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 笔记本         <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">999.999</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">4</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 智能手机          <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">999.999</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">5</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 洗衣机         <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">999.999</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 黑白电视机        <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">999.999</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">7</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 智能机器人          <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">999.999</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">8</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 彩色电视          <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">999.999</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">|</span>  <span style="color: rgba(128, 0, 0, 1); font-weight: bold">9</span> <span style="color: rgba(128, 128, 128, 1)">|</span> 沙发          <span style="color: rgba(128, 128, 128, 1)">|</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">999.999</span> <span style="color: rgba(128, 128, 128, 1)">|</span>
    <span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">--+------------+---------+</span>
    <span style="color: rgba(128, 0, 0, 1); font-weight: bold">9</span> rows <span style="color: rgba(128, 128, 128, 1)">in</span> <span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <p>Truncate操作演示:</p>
    <div class="cnblogs_code">
    <pre>mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> start <span style="color: rgba(0, 0, 255, 1)">transaction</span><span style="color: rgba(0, 0, 0, 1)">;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">truncate</span> <span style="color: rgba(0, 0, 255, 1)">table</span><span style="color: rgba(0, 0, 0, 1)"> product;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">select</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> product;
    Empty </span><span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">rollback</span><span style="color: rgba(0, 0, 0, 1)">;
    Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)
    
    mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">select</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> product;
    Empty </span><span style="color: rgba(0, 0, 255, 1)">set</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span> sec)</pre>
    </div>
    <h4>注意：delete删除，uid不会重置！而使用truncate操作，uid会重置[因为它删除了表结构，然后再创建一张一模一样的表，所以再次插入数据的数据的时候从1开始。</h4>
    <h3><span style="line-height: 1.5">查询操作</span></h3>
    <p>先创建表并添加数据</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">CREATE</span> <span style="color: rgba(0, 0, 255, 1)">TABLE</span><span style="color: rgba(0, 0, 0, 1)"> zhangwu (
      id </span><span style="color: rgba(0, 0, 255, 1)">INT</span> <span style="color: rgba(0, 0, 255, 1)">PRIMARY</span> <span style="color: rgba(0, 0, 255, 1)">KEY</span> AUTO_INCREMENT, <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 账务ID</span>
      zname <span style="color: rgba(0, 0, 255, 1)">VARCHAR</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">200</span>), <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 账务名称</span>
      zmoney <span style="color: rgba(0, 0, 255, 1)">DOUBLE</span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 金额</span>
    <span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> zhangwu(id,zname,zmoney) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">吃饭支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">247</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> zhangwu(id,zname,zmoney) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">工资收入</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">12345</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> zhangwu(id,zname,zmoney) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">3</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">服装支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1000</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> zhangwu(id,zname,zmoney) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">4</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">吃饭支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">325</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> zhangwu(id,zname,zmoney) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">股票收入</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">8000</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> zhangwu(id,zname,zmoney) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">打麻将支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">8000</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> zhangwu(id,zname,zmoney) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">7</span>,<span style="color: rgba(0, 0, 255, 1)">NULL</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5000</span>);</pre>
    </div>
    <p>语法：</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">select</span> <span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">distinct</span><span style="color: rgba(255, 0, 0, 1)">]</span> <span style="color: rgba(128, 128, 128, 1)">*|</span> 列名，列名 <span style="color: rgba(0, 0, 255, 1)">from</span> 表名 <span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">where条件</span><span style="color: rgba(255, 0, 0, 1)">]</span></pre>
    </div>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
       查询指定列的数据
       格式:select 列名1,列名2 from 表名
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> zname,zmoney <span style="color: rgba(0, 0, 255, 1)">FROM</span><span style="color: rgba(0, 0, 0, 1)"> zhangwu;
    
    </span><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
      查询所有列的数据
      格式:select * from 表名
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span><span style="color: rgba(0, 0, 0, 1)"> zhangwu;
    
    </span><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
       查询去掉重复记录
       DISTINCT 关键字 跟随列名
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span>  <span style="color: rgba(0, 0, 255, 1)">DISTINCT</span> zname <span style="color: rgba(0, 0, 255, 1)">FROM</span><span style="color: rgba(0, 0, 0, 1)"> zhangwu
    
    </span><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
      查询重新命名列
      as 关键字
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> zname <span style="color: rgba(0, 0, 255, 1)">AS</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">name</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span><span style="color: rgba(0, 0, 0, 1)"> zhangwu 
    
    </span><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
      查询数据中,直接进行数学计算
      列对数字进行计算
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> zname,zmoney<span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1000</span> <span style="color: rgba(0, 0, 255, 1)">AS</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">sum</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span><span style="color: rgba(0, 0, 0, 1)"> zhangwu
    
    </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 查询所有的吃饭支出</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zname<span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">吃饭支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>
    
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 查询金额大于1000</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zmoney<span style="color: rgba(128, 128, 128, 1)">&gt;</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1000</span>
    
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 查询金额在2000到5000之间 </span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zmoney <span style="color: rgba(128, 128, 128, 1)">&gt;=</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">2000</span> <span style="color: rgba(128, 128, 128, 1)">AND</span> zmoney <span style="color: rgba(128, 128, 128, 1)">&lt;=</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">5000</span>
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 改造成between and 方式</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zmoney <span style="color: rgba(128, 128, 128, 1)">BETWEEN</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">2000</span> <span style="color: rgba(128, 128, 128, 1)">AND</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">5000</span>
    
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 查询金额是 1000,3500,5000 其中一个</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zmoney <span style="color: rgba(128, 128, 128, 1)">=</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">1000</span> <span style="color: rgba(128, 128, 128, 1)">OR</span> zmoney<span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">3500</span> <span style="color: rgba(128, 128, 128, 1)">OR</span> zmoney<span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">5000</span>
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 改造成in方式</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zmoney  <span style="color: rgba(128, 128, 128, 1)">IN</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1000</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">3500</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5000</span><span style="color: rgba(0, 0, 0, 1)">)
    
    </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> like 模糊查询 配合通配符</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)"> 查询所有的支出</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zname <span style="color: rgba(128, 128, 128, 1)">LIKE</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">%支出%</span><span style="color: rgba(255, 0, 0, 1)">'</span>
    
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 查询账务名字,五个字符的</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zname <span style="color: rgba(128, 128, 128, 1)">LIKE</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">_____</span><span style="color: rgba(255, 0, 0, 1)">'</span>
    
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 查询账务名,不为空的</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zname <span style="color: rgba(0, 0, 255, 1)">IS</span> <span style="color: rgba(128, 128, 128, 1)">NOT</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>
    
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span>   <span style="color: rgba(128, 128, 128, 1)">NOT</span> ( zname <span style="color: rgba(0, 0, 255, 1)">IS</span> <span style="color: rgba(0, 0, 255, 1)">NULL</span>)</pre>
    </div>
    <h3>排序</h3>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
      查询,对结果集进行排序
      升序,降序,对指定列排序
      order by 列名 [desc][asc]
      desc 降序
      asc  升序排列,可以不写
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 查询账务表,价格进行升序</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">ORDER</span> <span style="color: rgba(0, 0, 255, 1)">BY</span> zmoney <span style="color: rgba(0, 0, 255, 1)">ASC</span>
    
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 查询账务表,价格进行降序</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">ORDER</span> <span style="color: rgba(0, 0, 255, 1)">BY</span> zmoney <span style="color: rgba(0, 0, 255, 1)">DESC</span>
    
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 查询账务表,查询所有的支出,对金额降序排列</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)"> 先过滤条件 where 查询的结果再排序</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zname <span style="color: rgba(128, 128, 128, 1)">LIKE</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">%支出%</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">ORDER</span> <span style="color: rgba(0, 0, 255, 1)">BY</span> zmoney <span style="color: rgba(0, 0, 255, 1)">DESC</span></pre>
    </div>
    <h3>聚合函数</h3>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
       使用聚合函数查询计算
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
    
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> count 求和,对表中的数据的个数求和  count(列名)</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)"> 查询统计账务表中,一共有多少条数据</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(255, 0, 255, 1)">COUNT</span>(<span style="color: rgba(128, 128, 128, 1)">*</span>)<span style="color: rgba(0, 0, 255, 1)">AS</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">count</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span><span style="color: rgba(0, 0, 0, 1)"> zhangwu
    
    </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> sum求和,对一列中数据进行求和计算 sum(列名)</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)"> 对账务表查询,对所有的金额求和计算</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(255, 0, 255, 1)">SUM</span>(zmoney) <span style="color: rgba(0, 0, 255, 1)">FROM</span><span style="color: rgba(0, 0, 0, 1)"> zhangwu
    </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 求和,统计所有支出的总金额</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(255, 0, 255, 1)">SUM</span>(zname) <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zname <span style="color: rgba(128, 128, 128, 1)">LIKE</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">%收入%</span><span style="color: rgba(255, 0, 0, 1)">'</span>
    
    <span style="color: rgba(0, 0, 255, 1)">INSERT</span> <span style="color: rgba(0, 0, 255, 1)">INTO</span> zhangwu (zname) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">彩票收入</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">)
    
    </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> max 函数,对某列数据,获取最大值</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(255, 0, 255, 1)">MAX</span>(zmoney) <span style="color: rgba(0, 0, 255, 1)">FROM</span><span style="color: rgba(0, 0, 0, 1)"> zhangwu
    
    </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> avg 函数,计算一个列所有数据的平均数</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(255, 0, 255, 1)">AVG</span>(zmoney)<span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu</pre>
    </div>
    <h3>分组操作</h3>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
        查询所有的数据
        吃饭支出 共计多少
        工资收入 共计多少
        服装支出 共计多少
        股票收入 共计多少
        打麻将支出 共计多少钱
        
        分组查询:  group by 被分组的列名
        必须跟随聚合函数
        select 查询的时候,被分组的列,要出现在select 选择列的后面
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
      <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(255, 0, 255, 1)">SUM</span>(zmoney),zname <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">GROUP</span> <span style="color: rgba(0, 0, 255, 1)">BY</span><span style="color: rgba(0, 0, 0, 1)"> zname
      
    </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 对zname内容进行分组查询求和,但是只要支出</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(255, 0, 255, 1)">SUM</span>(zmoney)<span style="color: rgba(0, 0, 255, 1)">AS</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">getsum</span><span style="color: rgba(255, 0, 0, 1)">'</span>,zname <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zname <span style="color: rgba(128, 128, 128, 1)">LIKE</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">%支出%</span><span style="color: rgba(255, 0, 0, 1)">'</span>
    <span style="color: rgba(0, 0, 255, 1)">GROUP</span> <span style="color: rgba(0, 0, 255, 1)">BY</span><span style="color: rgba(0, 0, 0, 1)"> zname
    </span><span style="color: rgba(0, 0, 255, 1)">ORDER</span> <span style="color: rgba(0, 0, 255, 1)">BY</span> getsum <span style="color: rgba(0, 0, 255, 1)">DESC</span>
    
    <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 对zname内容进行分组查询求和,但是只要支出, 显示金额大于5000</span><span style="color: rgba(0, 128, 128, 1)">
    --</span><span style="color: rgba(0, 128, 128, 1)"> 结果集是分组查询后,再次进行筛选,不能使用where, 分组后再次过滤,关键字 having</span>
    <span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(255, 0, 255, 1)">SUM</span>(zmoney)<span style="color: rgba(0, 0, 255, 1)">AS</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">getsum</span><span style="color: rgba(255, 0, 0, 1)">'</span>,zname <span style="color: rgba(0, 0, 255, 1)">FROM</span> zhangwu <span style="color: rgba(0, 0, 255, 1)">WHERE</span> zname <span style="color: rgba(128, 128, 128, 1)">LIKE</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">%支出%</span><span style="color: rgba(255, 0, 0, 1)">'</span>
    <span style="color: rgba(0, 0, 255, 1)">GROUP</span> <span style="color: rgba(0, 0, 255, 1)">BY</span> zname <span style="color: rgba(0, 0, 255, 1)">HAVING</span> getsum<span style="color: rgba(128, 128, 128, 1)">&gt;</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">5000</span></pre>
    </div>
    <h3>查询总结</h3>
    <ul>
    <li>select 一般在后面的内容都是要查询的字段</li>
    <li>from 要查询到表</li>
    <li>where</li>
    <li>group by</li>
    <li>having 分组后带有条件只能使用having</li>
    <li>order by 它必须放到最后面</li>
    </ul>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170720124600630-1491758387.png" alt=""></p>
    <p>&nbsp;更多请参考：<a href="http://www.cnblogs.com/feifeifanye/p/5954811.html" target="_blank">《MySQL&nbsp;必知必会》读书总结</a>、<a href="http://www.cnblogs.com/rocomp/p/4833977.html" target="_blank">《MySQL必知必会》读书笔记</a></p>
    </div>
    
</body>
</html>